<template>
	<view>
		<view v-if="loading">
			<text>加载中... {{progress}}%</text>
			<progress :percent="progress" stroke-width="2" />
		</view>
		<view v-else>
			<text>加载完成</text>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'tJinDu',
		props: {
			//控制显示
			show: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				loading: true,
				progress: 0
			};
		},
		created() {
			
		},
		onReady() {
			// 监听plusready事件
			document.addEventListener('plusready', () => {
				const webview = plus.webview.currentWebview();

				// 监听加载进度事件
				webview.addEventListener('progress', (event) => {
					this.progress = Math.round(event.loaded / event.total * 100);
				});

				// 监听页面加载完成
				webview.addEventListener('loaded', () => {
					setTimeout(() => {
						this.loading = false;
					}, 500); // 延时隐藏进度条，确保页面已完全渲染
				});
			});
		}
	};
</script>